		TITLE DEFCLASS - Copyright (c) 1994 by SLR Systems

		INCLUDE MACROS
		INCLUDE	CLASSES
		INCLUDE	SEGMENTS
		INCLUDE	IO_STRUC

		PUBLIC	DEFINE_CLASS


		.DATA

		EXTERNDEF	SEG_COMBINE:BYTE,CLASS_TYPE:BYTE,CLASS_PLTYPE:BYTE,DEBUG_TYPES_SELECTED:BYTE

		EXTERNDEF	FIRST_CLASS_GINDEX:DWORD,LAST_CLASS_GINDEX:DWORD,CLASS_SECTION_GINDEX:DWORD,SEG_LEN:DWORD

		EXTERNDEF	CLASS_GARRAY:STD_PTR_S


		.CODE	PASS1_TEXT

		EXTERNDEF	INSTALL_CLASS:PROC


DEFINE_CLASS	PROC
		;
		;RETURNS EAX IS CLASS_INDEX, ECX IS PHYS
		;
		PUSH	EBX
		CALL	INSTALL_CLASS		;EAX IS CLASS, ECX IS PHYS
		ASSUME	ECX:PTR CLASS_STRUCT
		;
		MOV	DL,[ECX]._C_ORDER_FLAG
		MOV	BL,[ECX]._C_TYPE_FLAG
if	fg_plink
		BITT	OVERLAY_CLASS_DEFINED
		JZ	DEF_OVERLAY_CLASS
DOC_RET:
endif
		AND	DL,MASK DEF_ORDERED
		JZ	ORDER_CLASS
L1$:

if	any_overlays
		MOV	BL,[ECX]._C_PLTYPE
		MOV	CLASS_PLTYPE,BL
		MOV	EBX,[ECX]._C_SECTION_GINDEX
		MOV	CLASS_SECTION_GINDEX,EBX
endif
		MOV	DL,BL
		AND	BL,NOT MASK SEG_IN_DGROUP

		AND	DL,MASK SEG_CV_SYMBOLS1 + MASK SEG_CV_TYPES1
		JNZ	L2$

		MOV	CLASS_TYPE,BL
		POP	EBX

		RET

if	fg_plink

DEF_OVERLAY_CLASS:
		OR	[ECX]._C_PLTYPE,MASK SEG_OVERLAYABLE
		SETT	OVERLAY_CLASS_DEFINED
		JMP	DOC_RET
endif

L2$:
		;
		;FORCE COMBINE TO PUBLIC, ALIGN TO BYTE
		;
		MOV	CLASS_TYPE,BL
		MOV	EBX,102H

		MOV	WPTR SEG_COMBINE,BX	;AND ALIGN
		GETT	BL,CODEVIEW_FLAG	;ARE WE KEEPING ANY CODEVIEW INFO?

		OR	BL,BL
		JZ	SKIP_CV

		MOV	BL,DL
		MOV	DH,DEBUG_TYPES_SELECTED

		AND	BL,MASK SEG_CV_TYPES1
		JNZ	L23$

		AND	DH,MASK FL_DEBUG_LOCALS
		JZ	SKIP_CV

		POP	EBX

		RET

L23$:
		AND	DL,MASK SEG_CV_SYMBOLS1
		JNZ	L24$

		AND	DH,MASK FL_DEBUG_TYPES
		JZ	SKIP_CV

		POP	EBX

		RET

L24$:
		;
		;BOTH BITS SET, SOME BORLAND GARBAGE
		;
		AND	DH,MASK FL_DEBUG_TYPES + MASK FL_DEBUG_LOCALS
		JZ	SKIP_CV

		POP	EBX

		RET

SKIP_CV:
		XOR	EDX,EDX			;NO CODEVIEW
		POP	EBX

		MOV	SEG_LEN,EDX

		RET


ORDER_CLASS:
		GETT	DL,SKIP_ORDERING	;IF ORDERING A SEGMENT, DON'T

		OR	DL,DL
		JNZ	L1$			;LINK CLASS

		PUSH	EBX
		MOV	EBX,LAST_CLASS_GINDEX

		TEST	EBX,EBX
		JZ	CLASS_FIRST

		CONVERT	EBX,EBX,CLASS_GARRAY
if	fg_rom
		BITT	LAST_ORDER_SEGMENT	;A SEGMENT WAS ORDERED LAST?
		JNZ	DEF_SEGMENT_SPEC
endif
		MOV	[EBX].CLASS_STRUCT._C_NEXT_CLASS_GINDEX,EAX
DEF_SEGMENT_SPEC_RET:
CLASS_FIRST_RET:
		MOV	LAST_CLASS_GINDEX,EAX	;UPDATE LAST CLASS POINTER
		OR	[ECX]._C_ORDER_FLAG,MASK DEF_ORDERED

		POP	EBX
		JMP	L1$

CLASS_FIRST:
		MOV	FIRST_CLASS_GINDEX,EAX
		JMP	CLASS_FIRST_RET

if	fg_rom
DEF_SEGMENT_SPEC:
		;
		;LAST CLASS IS ACTUALLY A SEGMENT...
		;
		RESS	LAST_ORDER_SEGMENT	;THIS IS NOW A CLASS
		OR	ES:[DI]._SEG_ORDER_FLAG,MASK DEF_NEXT_DIFFERENT
		;DX:BX
		MOV	ES:[DI]._SEG_NEXT_SEG_GINDEX,DX
		JMP	DEF_SEGMENT_SPEC_RET

endif

DEFINE_CLASS	ENDP


		END

